import { InfoCrudMixin } from 'lin-mizar';
import { merge } from 'lodash';
import { Sequelize, Model, DataTypes } from 'sequelize';
import sequelize from '../lib/db';

class Elevator extends Model {
//   toJSON () {
//     const origin = {
//       name: this.id,
//       title: this.title,
//       author: this.author,
//       summary: this.summary,
//       image: this.image
//     };
//     return origin;
//   }
}

Elevator.init(
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    name: {
      type: Sequelize.STRING(50),
      allowNull: false,
      comment: '电梯名称'
    },
    type: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '电梯的分类：1：扶手电梯，2：人行道 3:客梯'
    },
    deviceNumber: {
      type: Sequelize.STRING(50),
      allowNull: false,
      comment: '设备编码'
    },
    fstNumber: {
      type: Sequelize.STRING(50),
      allowNull: false,
      comment: '丰盛町自编编号'
    },
    status: {
      type: Sequelize.INTEGER,
      allowNull: false,
      comment: '电梯状态： 1：正常 2:故障 3:停运'
    },
    floor: {
      type: Sequelize.INTEGER,
      allowNull: false,
      comment: '电梯所属楼层'
    },
    location: {
      type: Sequelize.STRING,
      allowNull: false,
      comment: '安装区域'
    },
    factoryNumber: {
      type: Sequelize.STRING,
      allowNull: false,
      comment: '出厂编号'
    }
  },
  merge(
    {
      sequelize,
      tableName: 'elevator',
      modelName: 'elevator'
    },
    InfoCrudMixin.options
  )
);

export { Elevator as ElevatorModel };
